<template>
  <div class="mod-menu">
    <el-form :inline="true" :model="dataForm">
      <el-form-item label="店铺名称">
        <el-input v-model="pamars.shop_name" placeholder="店铺名称" clearable></el-input>
      </el-form-item>
      <el-form-item label="审核状态">
        <el-select v-model="pamars.audit_status" clearable placeholder="审核状态">
          <el-option label="待审核" :value="0"></el-option>
          <el-option label="审核通过" :value="1"></el-option>
          <el-option label="审核不通过" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" row-key="Id" border style="width: 100%; ">
      <el-table-column prop="shop_name" align="center" label="店铺名称"></el-table-column>
      <el-table-column align="center" label="店铺所在区域">
        <template slot-scope="scope">
          <div> 店铺所在区域：{{scope.row.province_name}}{{scope.row.city_name}}{{scope.row.area_name}}{{scope.row.street_name}}{{scope.row.community_name}}</div>
        </template>
      </el-table-column>
      <el-table-column prop="address" align="center" label="店铺地址"></el-table-column>
      <el-table-column prop="shop_name" align="center" label="店铺名称"></el-table-column>
      <el-table-column align="center" label="运营信息">
        <template slot-scope="scope">
          <div>姓名：{{scope.row.loser}}</div>
          <div>手机：{{scope.row.mobile}}</div>
        </template>
      </el-table-column>

      <el-table-column align="center" label="门店图片">
        <template slot-scope="scope">
          <el-popover placement="left" title trigger="hover">
            <img :src="item" v-for="(item,index) in scope.row.store_images" :key="index" style="height: 200px;width: 150px;margin-right: 10px;">
            <img slot="reference" v-for="(item,index) in scope.row.store_images" @click="$openImg(item)" :src="item" :key="index" style="height: 60px;width: 45px;margin-right: 10px;">
          </el-popover>
        </template>
      </el-table-column>

      <el-table-column prop="audit_status" align="center" :formatter="statusFormatter" label="审核状态" width="120px">
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" label="操作" width="120px">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="lookOver(scope.row.id,0)">查看</el-button>
          <el-button type="text" size="small" class="c-error" v-if="scope.row.audit_status==0" @click="delAudit(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pamars.page" :page-sizes="[10, 20, 50, 100]" :page-size="pamars.limit" :total="totalPage" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <audit v-if="addOrUpdateVisible" ref="audit" @updataList='updataList'></audit>
    <!--查看-->
    <merchant-details v-if="details" ref="merchantDetails" @refreshDataList="getList"></merchant-details>
  </div>
</template>

<script>
import Audit from '../../shop/audit/audit'
import seviceApi from '@/api/serviceApi.js'
import merchantDetails from '../../shop/merchant-detail'
export default {
  data () {
    return {
      dataForm: {},
      pamars: {
        page: 1,
        limit: 10,
        shop_name: '',
        audit_status: ''
      },
      totalPage: 0,
      dataList: [],
      dataListLoading: false,
      addOrUpdateVisible: false,
      details: false
    }
  },
  components: {
    Audit,
    merchantDetails
  },
  mounted () {
    this.getList()
  },
  methods: {
    delAudit (id) {
      this.$confirm(`确定要删除该条数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        seviceApi.delApply(id).then(res => {
          if (res && res.data.code == 200) {
            this.$message({
              message: '删除成功',
              type: 'success'
            })
            this.getList()
          }
        })
      }).catch(() => { })
    },
    // 更新列表
    updataList (e) {
      if (e == 1) {
        this.getList()
      }
    },
    // 审核状态
    statusFormatter (row, column) {
      let status = row.audit_status
      if (status === 0) {
        return '待审核'
      } else if (status === 1) {
        return '审核通过'
      } else {
        return '审核不通过'
      }
    },
    // 新增 / 修改
    audit (id, auditStatus) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.audit.init(id, auditStatus)
      })
    },
    // 查看
    lookOver (id, type) {
      this.details = true
      this.$nextTick(() => {
        this.$refs.merchantDetails.init(id, type)
      })
    },
    getList () {
      seviceApi.recordupdateList(this.pamars).then(res => {
        if (res && res.data.code == 200) {
          for (var i = 0; i < res.data.page.list.length; i++) {
            if (res.data.page.list[i].identty_images) {
              res.data.page.list[i].identty_images = res.data.page.list[i].identty_images.split(',')
            }
            if (res.data.page.list[i].store_images) {
              res.data.page.list[i].store_images = res.data.page.list[i].store_images.split(',')
            }
          }
          this.dataList = res.data.page.list
          this.totalPage = res.data.page.totalCount
        }
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pamars.limit = val
      this.getList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pamars.page = val
      this.getList()
    },
    // 查询
    getDataList () {
      this.pamars.page = 1
      this.getList()
    }
  }
}
</script>
